﻿
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using SIS.Models.Test;
using SIS.Models.Users.Entities;
using SIS.Services.Test;
using SIS.Services.Users;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace SIS.Web.Controllers
{
    [Route("api")]
    public class XamarinServicesController : Controller
    {
        #region 构造函数
        private readonly IUserServices _userServices;
        private readonly ITestServices _testServices;
        public XamarinServicesController(IUserServices userServices, ITestServices testServices)
        {
            _userServices = userServices;
            _testServices = testServices;
        } 
        #endregion

        #region 系统默认方法
        // GET: api/<controller>
        [HttpGet]
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/<controller>/5
        [HttpGet("{id}")]
        public string Get(int id)
        {
            return "value";
        }

        // POST api/<controller>
        [HttpPost]
        public void Post([FromBody]string value)
        {
        }

        // PUT api/<controller>/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE api/<controller>/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
        #endregion

        #region 测试框架接口

        [HttpGet("GetAllTest")]
        public IList<TestEntity> GetAllTest()
        {
            return _testServices.GetAll();
        }

        #endregion

        #region 用户接口

        [HttpGet("GetAllUser")]
        public IList<UserInfoEntity> GetAllUser()
        {
            return _userServices.GetAll();
        } 

        [HttpPost("RegisterUser")]
        public int RegisterUser([FromBody]UserInfoEntity userInfo)
        {
            if(userInfo!=null)
            {
                userInfo.CreateDate = DateTime.Now;
                userInfo.LastUpdateDate = userInfo.CreateDate;
                userInfo.Status = true;
            }
            return _userServices.Insert(userInfo);
        }

        [HttpPost("Login")]
        public int Login([FromBody]UserInfoEntity userInfo)
        {
            return _userServices.LogIn(userInfo.Name, userInfo.PassWord);
        }

        #endregion

    }
}
